package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.service.StudentService;
import com.web.service.impl.StudentServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//删除
@WebServlet("/deleteStudent")
public class Delete extends HttpServlet {
    private StudentService studentService = new StudentServiceimpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码
        req.setCharacterEncoding("UTF-8");
        //设置响应编码
        resp.setCharacterEncoding("UTF-8");
        //设置响应类型
        resp.setContentType("application/json;charset=UTF-8");

        int id = Integer.parseInt(req.getParameter("id"));
        studentService.removeStudentById(id);
        ResponseResult result = new ResponseResult(200,null,"删除成功");
        resp.getWriter().write(JSON.toJSONString(result));
    }
}
